package com.lh.service.impl.center;

import com.lh.mapper.UsersMapper;
import com.lh.pojo.Users;
import com.lh.pojo.bo.center.UserInfoBO;
import com.lh.service.center.UserInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @program: foodie-dev
 * @description:
 * @author: LH
 * @create: 2022-05-25 09:31
 **/
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UsersMapper usersMapper;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public Users getUserInfo(String userId) {

        Users users = usersMapper.selectByPrimaryKey(userId);
        return users;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Users updateUserInfo(String userId, UserInfoBO userInfoBO) {

        Users users = new Users();
        BeanUtils.copyProperties(userInfoBO, users);
        users.setId(userId);
        users.setUpdatedTime(new Date());

        usersMapper.updateByPrimaryKeySelective(users);

        return getUserInfo(userId);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public Users uploadFace(String userId, String url) {

        Users users = new Users();
        users.setId(userId);
        users.setFace(url);
        users.setUpdatedTime(new Date());

        usersMapper.updateByPrimaryKeySelective(users);

        return getUserInfo(userId);
    }
}
